#ifndef DREAM_H
#define DREAM_H
using namespace std;
#include <QtCore/qobject.h>
#include <QtNetwork/QTcpSocket>
#include <QtNetwork/QTcpServer>
#include <QSslSocket>
#include <QDataStream>
#include "Crypter.h"
#include "json/json.h"
#include "tools.h"
class Universe;
class Dream:public QObject
{
     Q_OBJECT
    bool isAlive;
    quint32 mBlockSize;
    QString mName;
    bool isConnected;
    QSslSocket* mSocket;
    Crypter mCrypter;
    DataBlock sessionId,publicCipher,publicSign;
    Universe* Master;
public:
    Dream(Universe* master,int handle);
    ~Dream();
    bool IsAlive(){return isAlive;};
    public slots:
    void OnConnect();
    void OnDisconnect();
    void OnReceiveDataBlock();
    void OnError(QAbstractSocket::SocketError socketError);
    void SaveKey(const std::string& user,const std::string& key,const std::string& type);
    bool LoadKey(DataBlock& key,const std::string& user,const std::string& type);
    void SendMessage(const std::string& data);
    void OnRequest(Json::Value& root);
    QString GetName(){return mName;}

};

#endif // DREAM_H
